<template>
  <Card title="套餐统计" :loading="loading">
    <div ref="chartRef" :style="{ width, height }"></div>
  </Card>
</template>
<script lang="ts" setup>
  import { Ref, ref, watch } from 'vue';
  import { Card } from 'ant-design-vue';
  import { useECharts } from '/@/hooks/web/useECharts';
  const props = defineProps({
    loading: Boolean,
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: '300px',
    },
  });
  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  watch(
    () => props.loading,
    () => {
      if (props.loading) {
        return;
      }
      setOptions({
        tooltip: {
          trigger: 'item',
        },
        legend: {
          orient: 'vertical',
          left: 'left',
        },
        series: [
          {
            color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9','#FF0000','#871F78','#8E236B','#D9D9F3','#00FF00','#6B238E'],
            name: '访问来源',
            type: 'pie',
            radius: ['50%', '80%'],
            center: ['75%', '50%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2,
            },
            label: {
              show: false,
              position: 'center',
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '12',
                fontWeight: 'bold',
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              { value: 1048, name: '国内流量畅享199元融合套餐' },
              { value: 735, name: '农村5G畅享129元云融合套餐2022版' },
              { value: 580, name: '省内流量畅享159元融合套餐预付费)' },
              { value: 484, name: '农村5G畅享169元云融合套餐2022版' },
              { value: 200, name: '数智169元融合套餐5G终端礼包' },
              { value: 324, name: '畅享139元套餐终端礼包-麦芒11-24期' },
              { value: 560, name: '畅享139元套餐终端礼包-一体机（升腾VAR210）-24期' },
              { value: 723, name: '5G畅享229元融合套餐2020版' },
              { value: 200, name: '天翼畅享60GB159元融合套餐2018版' },
              { value: 506, name: '5G畅享118元云融合套餐' },
            ],
            animationType: 'scale',
            animationEasing: 'exponentialInOut',
            animationDelay: function () {
              return Math.random() * 100;
            },
          },
        ],
      });
    },
    { immediate: true }
  );
</script>
